package com.shenjialin.Game;

import com.shenjialin.Tank.Tank;
import com.shenjialin.util.Constant;

import java.awt.*;

/**
 * 子弹类 这个地方可以设置一个实体类 然后坦克和子弹都继承这一个实体类
 */
public class Bullet {
    // 子弹的类型
    public static final int BULLET_TYPE0 = 0;
    public static final int BULLET_TYPE1 = 1;
    private int bulletType = BULLET_TYPE0;
    // 子弹的默认速度默认为坦克速度的二倍
    public static final int DEFAULT_SPEED = Tank.DEFAULT_SPEED<<1;
    private int x,y;
    private int speed = DEFAULT_SPEED;
    private int dir;
    private int atk;
    private Color color;
    // 炮弹的半径
    public static final int RADIUS = 4;

    public static final int RADIUS1 = 120;

    private boolean visible = true;


    public Bullet(int x, int y, int dir, int atk,Color color,int bulletType) {
        this.x = x;
        this.y = y;
        this.dir = dir;
        this.atk = atk;
        this.color = color;
        this.bulletType = bulletType;
    }
    // 空参构造
    public Bullet(){

    }

    // 类设计的基本思路

    /**
     * 炮弹自身的绘制方法
     * @param g
     */
    public void draw(Graphics g) {
        if(visible) {
            logic();
            g.setColor(color);
            // 绘制炮弹的圆
            if(bulletType == BULLET_TYPE0) {
                g.fillOval(x-RADIUS,y-RADIUS,RADIUS<<1,RADIUS<<1);
            }else if(bulletType == BULLET_TYPE1) {
                g.fillOval(x-RADIUS1,y-RADIUS1,RADIUS1<<1,RADIUS1<<1);
            }
        }else{
            return;
        }

    }

    /**
     * 子弹的逻辑
     */
    private void logic() {
        move();
    }
    private void move() {
        switch (dir) {
            case Tank.DIR_UP:
                y -= speed;
                if(y < 0){
                    visible = false;
                }
                break;
            case Tank.DIR_DOWN:
                y += speed;
                if(y > Constant.FRAME_HEIGHT){
                    visible = false;
                }
                break;
            case Tank.DIR_LEFT:
                x -= speed;
                if(x < 0){
                    visible = false;
                }
                break;
            case Tank.DIR_RIGHT:
                x += speed;
                if(x > Constant.FRAME_WIDTH) {
                    visible = false;
                }
                break;
        }
    }
    public int getX() {
        return x;
    }


    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getSpeed() {
        return speed;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }

    public int getDir() {
        return dir;
    }

    public void setDir(int dir) {
        this.dir = dir;
    }

    public int getAtk() {
        return atk;
    }

    public void setAtk(int atk) {
        this.atk = atk;
    }
    public void setColor(Color color) {
        this.color = color;
    }
    public void setVisible(boolean visible){
        this.visible = visible;
    }
    public boolean isVisible() {
        return visible;
    }

    public void setBulletType(int bulletType) {
        this.bulletType = bulletType;
    }

    public int getBulletType() {
        return bulletType;
    }
}
